import { getAddressList } from '@/api/address'

export default {
  namespaced: true,
  state () {
    return {
      addressList: []
    }
  },
  mutations: {
    setAddressList (state, newList) {
      state.addressList = newList
    },
    // 本地删除地址信息
    delAddressById (state, index) {
      state.addressList.splice(index, 1)
      console.log(state.addressList)
    }
  },
  actions: {
    // 获取用户地址信息
    async getUserAddressList (context) {
      // await getAddressList().then(res => {
      //   console.log('res', res.data)
      //   if (res.data !== null) {
      //     context.commit('setAddressList', res.data)
      //   }
      // }).catch(err => {
      //   console.log('err', err)
      // })
      const { data } = await getAddressList()
      context.commit('setAddressList', data)
    }
  },
  getters: {
  }
}
